<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
?>
<style>

li
{
	padding-top:10px;
	padding-bottom:10px;
}

.specialtext1
{
	padding: 3px;
	border: 1px solid #bebebe;
	background: #FFE0B9;
	font-size: 8pt;
}

.specialtext2
{
	padding: 3px;
	border: 1px solid #bebebe;
	background: #EEE8AA;
	font-size: 8pt;
}

.specialtext3
{
	padding: 3px;
	border: 1px solid #bebebe;
	background: #E6E6FA;
	font-size: 8pt;
}

</style>

	<p><a href="index.html?page=addEntry">Add New <b>Root</b> Treeview Entry</a> / <a href="index.html?page=orderChildren&ID=0">Order Root Children</a></p>
	<?
	
	$sql="SELECT t.ID, t.name, t.link, t.parentID, t.roleID FROM treeEntry t  ORDER BY t.parentID, t.ord ASC";
	$result=db_fetch_array(db_query($sql));
	
	if (is_array($result))
	{
	?>
	<ul>
	<br />
			<?
			//Now we want to fill an array
			$i=0;
			foreach ($result as $row)
			{
				//If they are a parent
				$channelArray[$row["ID"]]["ID"]=$row["ID"];
				$channelArray[$row["ID"]]["name"]=$row["name"];
				$channelArray[$row["ID"]]["link"]=$row["link"];
				if ($row["roleID"]!="")
				{
					$channelArray[$row["ID"]]["restrictions"]=1;
				}
				if ($row["parentID"]>0)
				{
					$num=count($channelArray[$row["parentID"]]["sub"]);
					$channelArray[$row["parentID"]]["sub"][$num]=$row["ID"];
				}
			}
			
			
			$sql="SELECT t.name, t.parentID, t.ID, t.roleID FROM treeEntry t ORDER BY t.parentID, t.ord ASC";
			$result=run_mysql_query($sql);
			
			function arrayCheck($channelID)
			{
				global $channelDone, $channelArray;
				
				
				if (is_array($channelArray[$channelID]["sub"]))
				{
					for ($i=0;$i<count($channelArray[$channelID]["sub"]); $i++)
					{
						if ($channelArray[$channelArray[$channelID]["sub"][$i]]["restrictions"]==1)
						{
							$restText="<span class=\"smalltext\"><b class=\"highlight\">(R)</b></span>";
						}
						else
						{
							$restText="";
						}
						
						
						echo "<ul><li> ".$restText." <a href=\"index.html?page=editEntry&entryID=".$channelArray[$channelID]["sub"][$i]."\">".$channelArray[$channelArray[$channelID]["sub"][$i]]["name"]."</a>";
						echo " <span class=\"specialtext1\"><a href=\"query_treeview.php?action=deleteEntry&entryID=".$channelArray[$channelID]["sub"][$i]."\" onClick=\"javascript: return confirm('Delete: ".$channelArray[$channelArray[$channelID]["sub"][$i]]["name"]."?');\">delete</a></span>"."\n";

						echo " <span class=\"specialtext2\"><a href=\"index.html?page=addEntry&parentID=".$channelArray[$channelID]["sub"][$i]."\">add sub</a></span>"."\n";
						
						echo " <span class=\"specialtext3\"><a href=\"index.html?page=orderChildren&ID=".$channelArray[$channelID]["sub"][$i]."\">order children</a></span>"."\n";
						
						

						echo "</li>";
						
						$channelDone[$channelArray[$channelID]["sub"][$i]]=1;
						arrayCheck($channelArray[$channelID]["sub"][$i]);
						echo "</ul>"."\n";
					}
				}
			}
			
			echo "<ul class=\"special\">"."\n";
			
			while ($row=mysql_fetch_array($result))
			{
				if ($channelDone[$row["ID"]]!=1)
				{
					$currentParentID=$row["ID"];
					
					if ($row["roleID"]!="")
					{
						$restText="(R)";
					}
					else
					{
						$restText="";
					}
					echo "<li> ".$restText." <a href=\"index.html?page=editEntry&entryID=".$row["ID"]."\"><b>".$row["name"]."</b></a>";
					echo " <span class=\"specialtext1\"><a href=\"query_treeview.php?action=deleteEntry&entryID=".$row["ID"]."\" onClick=\"javascript: return confirm('Delete: ".$row["name"]."?');\">delete</a></span>"."\n";
					
					echo " <span class=\"specialtext2\"><a href=\"index.html?page=addEntry&parentID=".$row["ID"]."\">add sub</a></span>"."\n";
					
					echo " <span class=\"specialtext3\"><a href=\"index.html?page=orderChildren&ID=".$row["ID"]."\">order children</a></span>"."\n";
					
					echo "</li>";
					
					arrayCheck($row["ID"]);
					
				}
				
				
			}
			echo "</ul>"."\n";
			?>
	<br />
	<br />
	
	
	
	<?
		
	}
	else
	{
	?>
	<p>There are no entries in the table.</p>
	
	<?
		
	}
	
	
	?>
</ul>




	





